﻿using Mengsk.ProxyDelivery.Domain;
using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Accounting
{
    /// <summary>
    /// Interaction logic for SellerTradeMarkCompleteWindow.xaml
    /// </summary>
    public partial class SellerTradeMarkCompleteWindow : Window
    {
        public SellerPay SellerTrade { get; set; }
        public SellerTradeMarkCompleteWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                this.DataContext = SellerTrade;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.DialogResult = true;
            }
        }

        private void btnMarkComplete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SellerPayService sellerTradeService = ServiceContainer.GetService<SellerPayService>();
                string comment = this.tbComment.Text.Trim();
                string alipayaccount = this.tbPayAccount.Text.Trim();

                if (string.IsNullOrWhiteSpace(comment))
                {
                    MessageBox.Show("交易编号不能为空");
                    return;
                }

                if (string.IsNullOrWhiteSpace(alipayaccount))
                {
                    MessageBox.Show("支付账户不能为空");
                    return;
                }

                if (MessageBox.Show("确认提交", "提示", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                {
                    return;
                }

                sellerTradeService.MarkComplete(this.SellerTrade.Id, this.SellerTrade.SellerId, comment, alipayaccount);
                MessageBox.Show("已成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
